package com.common.listener;



import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * sesssion 生命周期监听
 * @author YYQ
 *
 */
@WebListener
public class MySessionListener implements HttpSessionListener {

	private SessionBean sessionBean = SessionBean.getSessionBean();
	private final Logger logger = LoggerFactory.getLogger(MySessionListener.class);
	
	@Override
	public void sessionCreated(HttpSessionEvent se) {
		logger.info(se.getSession().getId()+"---------Session创建");
		sessionBean.addSession(se.getSession().getId(), se.getSession());
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent se) {
		logger.info(se.getSession().getId()+"---------Session销毁");
		sessionBean.removeSession(se.getSession().getId());
	}

}
